package control;

import java.sql.SQLException;
import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.operator.OperatorService;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

public class OperatorController extends MultiActionController {
	private OperatorService operatorService;
	private MachineController mc;
	public void setmachineController(MachineController mc) {
		this.mc = mc;
	}
	public void setoperatorService(OperatorService operatorService){
		this.operatorService=operatorService;
	}
	
	// 운영자가 목표생산량과 목표불량량을 넣으면 디비에 들어가는거
	public void workOrderInsert(HttpServletRequest request,HttpServletResponse response) throws SQLException{
		int workorder_quantity = Integer.parseInt(request.getParameter("workorder_quantity"));
		int workorder_bad = Integer.parseInt(request.getParameter("workorder_bad"));
		String flag = request.getParameter("flag");
		//System.out.println("지시하기!! 컨트롤로 오나?"+workorder_quantity+"/"+workorder_bad+"/"+flag);
		HashMap map = new HashMap();
		map.put("workorder_quantity", workorder_quantity);
		map.put("workorder_badquantity", workorder_bad);
		if(flag.equals("update"))
			operatorService.workOrderUpdate(map); 
		else
			operatorService.workOrderInsert(map); 
		mc.setProduction_quantity(0);
		mc.setProduction_bad_quantity(0,0,0,0,0,0);
	}
	//통계결과 뽑아오기
	public ModelAndView operatorResultView(HttpServletRequest request,HttpServletResponse response) throws SQLException{
		//System.out.println("여기안오는겅???");
		HashMap result_map = new HashMap();
		result_map = operatorService.resultStatistics();
		System.out.println(result_map);
		return new ModelAndView("JsonView","result_map",result_map);
	}
	//실시간으로 값 올려주는 메서드구나... (machineController에 접근)
	public ModelAndView production_view(HttpServletRequest request,
			HttpServletResponse response) throws SQLException{
		HashMap production_map = mc.production_view();
		return new ModelAndView("JsonView","production_map",production_map);
	}
}
